def prost(x):
    conf = True
    for j in range(2, x // 2 + 1):
        if x % j == 0:
            conf = False
    return conf


a = {'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9}
n = input().split()
cont = True
for i in n:
    if i not in a:
        print('Wrong input')
        cont = False
        break
if cont:
    n = a[n[0]] * 100 + a[n[1]] * 10 + a[n[2]]
    for y in range(n):
        if prost(n - y):
            print(n - y)
            break
        elif prost(n + y):
            print(n + y)
            break
